<template>
	<view class="edit_password">
		<view class="form_box">
			<u-field type='text' :password='true' v-model="form.passWord" label-width='0' placeholder="请输入新密码">
			</u-field>
			<u-field type='text' :password='true' v-model="form.repeatPassWord" label-width='0' placeholder="请确认新密码">
			</u-field>
		</view>
		<u-button type='primary' shape="circle" @click="submit">立即修改</u-button>
	</view>
</template>

<script>
	import cacheFunc from '@/utils/cache.js'
	import {
		logOut
	} from '@/utils/logOut.js'
	export default {
		data() {
			return {
				form: {
					passWord: '',
					repeatPassWord: '',
				},
				telPhoneForm: null
			};
		},
		onReady() {
			// this.$refs.uForm.setRules(this.rules);
		},
		onLoad(e) {
			if (e && e.telPhoneForm) {

				this.telPhoneForm = JSON.parse(e.telPhoneForm)
				console.log(this.telPhoneForm)
			}
		},
		methods: {
			async submit() {
				if (!this.form.passWord) {
					this.$u.toast('请先输入密码!');
					return
				}

				if (!this.form.repeatPassWord) {
					this.$u.toast('请再次输入密码!');
					return
				}
				if (this.form.repeatPassWord != this.form.passWord) {
					this.$u.toast('两次输入密码不一致,请检查!');
					return
				}
				if (this.telPhoneForm == null) {
					this.$u.api.setPassword({
						passWord: this.form.passWord
					}).then(res => {
						logOut('修改成功,请从新登陆!')
					})
				} else {
					this.$u.api.forgetPassword({
						phoneNum: this.telPhoneForm.telPhone,
						code: this.telPhoneForm.code,
						password: this.form.passWord
					}).then(res => {
						logOut('修改成功,请从新登陆!')
					})
				}


			},

		}
	}
</script>

<style lang="scss" scoped>
	.edit_password {
		padding: 0 30rpx;

		.form_box {
			margin-bottom: 100rpx;
		}
	}
</style>
